Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace generated Archtest by TechnicalStructureTest #17521

Conversation

codecholeric
Copy link
Contributor

@codecholeric codecholeric commented Jan 8, 2022

Since the generated application is modelled after a simple layered architecture we can provide a generated ArchUnit test that uses Architectures.layeredArchitecture() as a nice example of a higher abstraction architecture rule. This will assert even more dependencies for correctness than before (for example no dependencies from repositories to services). Furthermore, by specifying an exact list of which layer is allowed to access which other layer, instead of forbidding specific dependencies from one layer to another, we remove one potential source of accidental violation. E.g., by forbidding service -> web we can still have accesses like services -> some_utils_no_one_cares_about -> web. If we specify that no other layer may access web (because all accesses are via REST, etc., and not from other Java code), we can make sure that there are no accidental dependencies through some unexpected packages.

I've also replaced the manual import via new ClassFileImporter()...importPackages(..) by ArchUnit's JUnit 5 support. The dependency was already correct anyway, and it allows to write the test a little more concisely and automatically brings caching between multiple rules that import the same classes.

Related: #17520


Please make sure the below checklist is followed for Pull Requests.

When you are still working on the PR, consider converting it to Draft (below reviewers) and adding skip-ci label, you can still see CI build result at your branch.

@CLAassistant
Copy link

CLAassistant commented Jan 8, 2022

CLA assistant check
All committers have signed the CLA.

@codecholeric
Copy link
Contributor Author

When I forgot to push DoNotIncludeTests on the arch test I noticed that a lot of tests have a dependency domain -> web.rest.TestUtil.equalsVerifier(java.lang.Class) which seems a little weird to me 🤔
The top level Javadoc says "Utility class for testing REST controllers" but then the Javadoc on equalsVerifier suddenly talks about the domain object, i.e. deals with objects from domain.
Would feel cleaner to me if this equalsVerifier method would reside in test utils within domain if it deals with domain objects 🤷‍♂️ But for now I've added back "ignore tests" so at least the arch test shouldn't fail anymore because of that...

Since the generated application is modelled after a simple layered architecture we can provide a generated ArchUnit test that uses `Architectures.layeredArchitecture()` as a nice example of a higher abstraction architecture rule. This will assert even more dependencies for correctness than before (for example no dependencies from repositories to services). Furthermore, by specifying an exact list of which layer is allowed to access which other layer, instead of forbidding specific dependencies from one layer to another, we remove one potential source of accidental violation. E.g., by forbidding `service -> web` we can still have accesses like `services -> some_utils_no_one_cares_about -> web`. If we specify that no other layer may access web (because all accesses are via REST, etc., and not from other Java code), we can make sure that there are no accidental dependencies through some unexpected packages.

 I've also replaced the manual import via `new ClassFileImporter()...importPackages(..)` by ArchUnit's JUnit 5 support. The dependency was already correct anyway, and it allows to write the test a little more concisely and automatically brings caching between multiple rules that import the same classes.

Resolves: jhipster#17520
@codecholeric
Copy link
Contributor Author

Hmm, I'm a little stuck I think. Because, the reactive configurations create the following dependency repository.rowmapper.UserRowMapper -> service.ColumnConverter. So this is in turn a cyclic constellation service -> repository -> service. Was it intended this way? It seems a little strange that logic to convert DB columns resides in the service layer? 🤔
Or I was wrong in the first place and this was never supposed to be layered this way, but then I still think a cycle between repository and service is weird in any case? (I would think one way or the other this should be directed on the static level?)
Anyway, I don't know exactly how I should go on, because I'm not sure what the original intentions were. Maybe somebody who knows why the code was designed like this originally can give me a hint? 🙏

@pascalgrimaud
Copy link
Member

From my point of view, your arch tests are correct.

If we have service -> repository -> service, it's a mistake and it means our ArchTests need to be improved to detect this kind of code.

@mshima
Copy link
Member

mshima commented Jan 9, 2022

Or I was wrong in the first place and this was never supposed to be layered this way, but then I still think a cycle between repository and service is weird in any case? (I would think one way or the other this should be directed on the static level?)
Anyway, I don't know exactly how I should go on, because I'm not sure what the original intentions were. Maybe somebody who knows why the code was designed like this originally can give me a hint?

It’s open source, and community based. Unless we have good tests in place and enforce code standards it’s hard to keep good code standards every time.

I think your PR looks correct, we should fix the implementation.
If I may, I will merge to a branch at main repository, so we can continue the work from there.

@codecholeric
Copy link
Contributor Author

@mshima Sure, feel free to do what you want! Does this mean you would take over the change from this PR and adjust the implementation then? In any case, just let me know if you want me to change something / take further action in any direction!

@mshima
Copy link
Member

mshima commented Jan 10, 2022

Looks like there is only 1 failure. Should be easy to fix.

@mshima mshima closed this Jan 11, 2022
@mshima mshima reopened this Jan 11, 2022
@mshima mshima changed the base branch from main to skip_ci-technical_structure_test January 12, 2022 13:06
@mshima
Copy link
Member

mshima commented Jan 12, 2022

#17542 wasn’t enough, moving to a branch at main repository.

@mshima mshima merged commit 5138c9b into jhipster:skip_ci-technical_structure_test Jan 12, 2022
@pascalgrimaud pascalgrimaud added this to the 7.6.0 milestone Jan 12, 2022
@codecholeric codecholeric deleted the extend-arch-test branch January 13, 2022 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce more sophisticated ArchUnit architecture test
4 participants